package com.fafu.tool;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import javax.mail.internet.MimeMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper;

public class MailUtils587 {
	private static JavaMailSenderImpl javaMailSender;
	private static String userName ;
	List <String>adress = new ArrayList();
	List <String>password =new ArrayList();

	/*static {
		List <String>adress = new ArrayList();
		List <String>password =new ArrayList();
		//海
		adress.add("1014755647@qq.com");
		password.add("exjqfubnuatqbdhg");
		//灿
		adress.add("1066619570@qq.com");
		password.add("ayhwnrwuqqwybbfh");
		//灿
		adress.add("3480136305@qq.com");
		password.add("exxkrwalbdcgcjdh");
		//航
		adress.add("1506718217@qq.com");
		password.add("bmgoxitrnyakiaaj");
		//彬
		adress.add("798430617@qq.com");
		password.add("htsggiemrsipbeeb");
		//臣
		adress.add("1319725146@qq.com");
		password.add("bxgyzypwkxbihacc");
		//尉
		adress.add("1125030435@qq.com");
		password.add("wnkdzqpeudfsicjg");
		//浩
		adress.add("1311405073@qq.com");
		password.add("xfkxvuynjsrqgjch");
		int number = (int) (0 + Math.random() * 7);
		userName = adress.get(number);
		String code = password.get(number);


		javaMailSender = new JavaMailSenderImpl();
		javaMailSender.setHost("smtp.qq.com");// 连接服务器
		javaMailSender.setUsername(userName);// 账号
		javaMailSender.setPassword(code);// 密码
		javaMailSender.setDefaultEncoding("UTF-8");
		Properties properties = new Properties();

		// 设置通过ssl协议使用587端口发送、使用默认端口（25）时下面三行不需要
		properties.setProperty("mail.smtp.auth", "true");// 开启认证
		properties.setProperty("mail.smtp.socketFactory.port", "587");// 设置ssl端口
		properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
		javaMailSender.setJavaMailProperties(properties);
	}*/

	public MailUtils587(){
		adress = new ArrayList();
		password =new ArrayList();
		//海
		adress.add("1014755647@qq.com");
		password.add("exjqfubnuatqbdhg");
		//灿
		adress.add("1066619570@qq.com");
		password.add("ayhwnrwuqqwybbfh");
		//灿
		adress.add("3480136305@qq.com");
		password.add("exxkrwalbdcgcjdh");
		//航
		adress.add("1506718217@qq.com");
		password.add("bmgoxitrnyakiaaj");
		//彬
		adress.add("798430617@qq.com");
		password.add("htsggiemrsipbeeb");
		//臣
		adress.add("1319725146@qq.com");
		password.add("bxgyzypwkxbihacc");
		//尉
		adress.add("1125030435@qq.com");
		password.add("wnkdzqpeudfsicjg");
		//浩
		adress.add("1311405073@qq.com");
		password.add("xfkxvuynjsrqgjch");
		int number = (int) (0 + Math.random() * 7);
		userName = adress.get(number);
		String code = password.get(number);


		javaMailSender = new JavaMailSenderImpl();
		javaMailSender.setHost("smtp.qq.com");// 连接服务器
		javaMailSender.setUsername(userName);// 账号
		javaMailSender.setPassword(code);// 密码
		javaMailSender.setDefaultEncoding("UTF-8");
		Properties properties = new Properties();

		// 设置通过ssl协议使用587端口发送、使用默认端口（25）时下面三行不需要
		properties.setProperty("mail.smtp.auth", "true");// 开启认证
		properties.setProperty("mail.smtp.socketFactory.port", "587");// 设置ssl端口
		properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
		javaMailSender.setJavaMailProperties(properties);
	}

	public void sendEmail(final String title, final String content, final String toMail) {

		new Thread(new Runnable() {// 开启线程异步发送 防止发送请求时间过长
			@Override
			public void run() {
				try {
					if (!toMail.equals("")) {
						String[] toAddress = toMail.split(",");
						MimeMessage message = javaMailSender.createMimeMessage();
						MimeMessageHelper helper = new MimeMessageHelper(message, true, "utf-8");
						helper.setFrom(userName);
						helper.setTo(toAddress);
						helper.setSubject(title);
						helper.setText(content, true); // 内容
						javaMailSender.send(message); // 发送邮件
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		}).start();
	}
	//测试发送
	/*public static void main(String[] args) {
		sendEmail("title", "123", "1125030435@qq.com");
		System.out.println("fas");
	}*/

}